package com.fhz.day004;

import androidx.appcompat.app.AppCompatActivity;
import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentTransaction;

import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;

import java.util.Timer;
import java.util.TimerTask;

public class MainActivity extends AppCompatActivity {


    //logt
    private static final String TAG = "MainActivity";
    HomeFragment homeFragment ;

    User user;
    Timer timer;
    //创建布局和初始化组件的
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);


        //栈的id
        int taskId = getTaskId();
        Log.i(TAG, "onCreate: "+taskId);

//        startActivity(int);

//        new Intent(this,?)
        user = new User();
        timer = new Timer();

        homeFragment  = new HomeFragment();
    }

    @Override
    protected void onRestart() {
        super.onRestart();
    }

    //瞬时态
    @Override
    protected void onStart() {
        super.onStart();
    }


    //用户课交互
    @Override
    protected void onResume() {
        super.onResume();
//        timer.schedule(new TimerTask() {
//            @Override
//            public void run() {
//                //logi
////                Log.i(TAG, "run: ");
//            }
//        },0,1000);
    }


    @Override
    protected void onPause() {
        super.onPause();
    }


    @Override
    protected void onStop() {
        super.onStop();
    }



    @Override
    protected void onDestroy() {
        super.onDestroy();
        user = null;
        timer.cancel();
    }



    public void add(View view) {

        //frament管理
        FragmentManager supportFragmentManager = getSupportFragmentManager();
        //事务
        FragmentTransaction fragmentTransaction = supportFragmentManager.beginTransaction();

        fragmentTransaction.add(R.id.ll,homeFragment);

        fragmentTransaction.addToBackStack("123");
        //添加
//        fragmentTransaction.add(R.id.ll,homeFragment);
        //移除
//        fragmentTransaction.remove(homeFragment);
        //替换
//        fragmentTransaction.replace(R.id.ll, new HomeFragment());

        //显示
//        fragmentTransaction.hide(homeFragment);
        //隐藏
//        fragmentTransaction.show(homeFragment);

        fragmentTransaction.commit();


    }

    public void del(View view) {
        //frament管理
        FragmentManager supportFragmentManager = getSupportFragmentManager();
        //事务
        FragmentTransaction fragmentTransaction = supportFragmentManager.beginTransaction();

        fragmentTransaction.remove(homeFragment);

        fragmentTransaction.commit();

    }
}